﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class shop_ShopManager : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Utility.InitUltraWebGrid.InitDisplayLayOut(this.uwgShop);

            if (_Site != null)
            {
                hSiteID.Text = _Customer.ShopID.ToString();
            }

            BindData();           
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        RequestCompetences = Competences.BuildCompetencesList(Competences.SurrogateO);//页面权限

        base.OnLoad(e);
    }

    #endregion

    protected void uwgShop_PageIndexChanged(object sender, Infragistics.WebUI.UltraWebGrid.PageEventArgs e)
    {
        this.BindData();
    }

    private void BindData()
    {
        DataTable dt = null;
        long ShopID = Shove._Convert.StrToLong(hSiteID.Text, 0);

        if (ShopID == 1)
        {
            dt = new DAL.Views.V_Shop().Open("", "", "ID");
        }
        else
        {
            dt = new DAL.Views.V_Shop().Open("", "[ID] = " + ShopID, "");
        }

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无您需要的数据", "ShopManager");

            return;
        }

        uwgShop.DataSource = dt;
        uwgShop.DataBind();
    }

    protected void btStart_Click(object sender, EventArgs e)
    {
        long ID = Shove._Convert.StrToLong(hSuperID.Value, 0);
        string SiteURL = hSiteURL.Value;

        DAL.Tables.tbl_Shop tbl_Shop = new DAL.Tables.tbl_Shop();
        tbl_Shop.SiteStatus.Value = 1;        

        if (tbl_Shop.Update("ID=" + ID) >= 0)
        {
            //PublicFunction.BindHostHeader(SiteURL);      //梆定到IIS主机头上

            BindData();
        }
        else
        {
            Shove._Web.JavaScript.Alert(this.Page, "此网店已经开通！");
        }

        this.hSuperID.Value = "";
    }

    protected void btStop_Click(object sender, EventArgs e)
    {
        long ID = Shove._Convert.StrToLong(hSuperID.Value, 0);
        DAL.Tables.tbl_Shop tbl_Shop = new DAL.Tables.tbl_Shop();
        tbl_Shop.SiteStatus.Value = 0;

        if (tbl_Shop.Update("ID=" + ID) >= 0)
        {
            BindData();
        }
        else
        {
            Shove._Web.JavaScript.Alert(this.Page, "此网店已经开通！");
        }

        this.hSuperID.Value = "";
    }
}
